<template>
  <DataList :name="name" :cate="cate" :cols="cols" 
  :single="true"/>
</template>
<script>
import DataList from "@/components/DataList";
import { getUser } from "@/utils/auth";
import { search教师基本情况, get教师基本情况ByGH } from "@/api/教师基本情况";
import { addXxhjg, deleteXxhjg, updateXxhjg, getXxhjg } from "@/api/信息化工作机构与人员.js";
import { get机构设置ByGH,get机构设置 } from "@/api/机构设置";
import { get教工基本情况 } from "@/api/教师基本情况";
import linq from "linq"
export default {
  components: {
    DataList
  },
  data() {
    return {
      cate: "A3-4-3信息化工作机构与人员",
      name:'3.4.3 信息化工作机构与人员',
      cols: [
        { label: "机构代码", prop: "XXHJGDM" },
        { label: "机构名称(全称)", prop: "XXHJGMC" },
        { label: "负责人教工号", prop: "GH" },
        { label: "负责人姓名", prop: "XM" },
        { label: "专职人员数(个)", prop: "ZZRS" },
        { label: "兼职人员数(个)", prop: "JZRS" },
        
      ]
    };
  },
  methods: {
    check(array,list) {
     
    },
    async fetchData() {
      var user = getUser();
      var datas = await getXxhjg(user.XXID,user.CJPC);
      return datas;
    },
    
    onadd(model){
      var temp = JSON.parse(JSON.stringify(model))
      
      return new Promise(async (resolve,reject)=>{
          console.log(JSON.stringify(temp));
          var model = await addXxhjg(temp);
          resolve(model);
      })
    },
    async  onChange(model, field, value) {
      
       if(field == "GH"){
         if(value == "error"){
           console.log("error")
          model.GH="";
          model.XM= "";
          model.XXHJGDM="";
          model.XXHJGMC=""

          
          
         }else{
         var d1 =  await get教师基本情况ByGH(this.$root.user.XXID,this.$root.user.CJPC,value);
        
         
           console.log("udpate ")
          model.XM= d1[0].XM;
          model.XXHJGDM=d1[0].BMBH;
          model.XXHJGMC=d1[0].BMMC;
         
         
         }
       }
      //
    },
    onupdate(model) {
      //
      var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
           
          console.log(JSON.stringify(temp));
          var model = await updateXxhjg(temp);
          resolve(model);
      })
      //
    },
    ondelete(model) {
       var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
        
         await deleteXxhjg(temp);
          resolve();
      })
    }
  }
};
</script>
<style>
</style>